package com.me.bbs.controller_advice;

import com.me.bbs.common.CommonConst;
import com.me.bbs.common.Resp;
import com.me.bbs.exceptions.BanException;
import com.me.bbs.exceptions.NoAuthException;
import com.me.bbs.exceptions.NoLoginException;
import com.me.bbs.exceptions.NotExistException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * @author Liming Wang
 * @Description
 * @Create 2023/1/10 18:19
 */
//@RestController
@ControllerAdvice
public class HandlerController {
    @ResponseBody
    @ExceptionHandler(NoLoginException.class)
    public Resp<?> handleNoLogin(Exception e) {

        return Resp.error(CommonConst.NO_LOGIN_CODE,"请登陆后再进行操作");
    }
    @ResponseBody
    @ExceptionHandler(NoAuthException.class)
    public Resp<?> handleNoAuth(Exception e) {

        return Resp.error(CommonConst.NO_AUTH_CODE,"无权限");
    }
    @ResponseBody
    @ExceptionHandler(BanException.class)
    public Resp<?> handleBan(Exception e) {

        return Resp.error(CommonConst.BAN_CODE,e.getMessage());
    }

    @ResponseBody
    @ExceptionHandler(NotExistException.class)
    public Resp<?> handleNotExists(Exception e) {
        return Resp.error(CommonConst.NOT_EXIST_CODE,"资源不存在");
    }

}
